import { Request, Response } from 'express';
import questionService from '../services/questionService';

export const getQuestionsByKnowledge = async (req: Request, res: Response): Promise<void> => {
  try {
    const { knowledge_code } = req.query;
    const questions = await questionService.getByKnowledge(knowledge_code as string);
    res.status(200).json(questions);
  } catch (error) {
    res.status(500).json({ message: (error as Error).message });
  }
};

export const generateQuestion = async (req: Request, res: Response): Promise<void> => {
  try {
    const newQuestion = await questionService.generate(req.body);
    res.status(201).json(newQuestion);
  } catch (error) {
    res.status(500).json({ message: (error as Error).message });
  }
};

export const getQuestionDetail = async (req: Request, res: Response): Promise<void> => {
  try {
    const question = await questionService.getById(req.params.id);
    res.status(200).json(question);
  } catch (error) {
    res.status(500).json({ message: (error as Error).message });
  }
};